<?php
/**
 * 
 * 获取/config下的配置文件信息
 * 只会获取.ini.php格式的配置文件,
 * @author Charles
 *
 */
class config  {

    static $config;

    /**
     * 读取配置信息
     */
    static function readcof($key = '', $explode = '.')
    {
		$key=empty($key)?'config':$key;
        $Ary = array();
        if (strpos($key, $explode) === false) {
            $Ary[] = $key;
        } else {
            $Ary = explode($explode, $key);
        }
        
        $class = $Ary[0];
        
        if (!isset(self::$config[$class])) {
            self::$config[$class] = getparseini($class.'.ini.php');
        }
        
        if (count($Ary) == 1) {
            return self::$config[$class];
        } elseif (count($Ary) >= 2) {
        	array_shift($Ary);
            $lkey = '';
            $tmpConfig=array();
            foreach ($Ary as $val) {
            	if(!empty($tmpConfig) && isset($tmpConfig[$val]))
            	{
            		$tmpConfig=$tmpConfig[$val];
            	}elseif(isset(self::$config[$class][$val]))
            	{
            		$tmpConfig=self::$config[$class][$val];
            	}
            }
 			return $tmpConfig;
        }
        return NULL;
    }

    /**
     * 修改配置信息
     */
    static function writecof($class, $key, $value)
    {
        self::$config[$class][$key] = $value;
    }
}
?>